package com.test.entity;

/**
 * 操作结果类. <br>
 * 对业务逻辑操作进行信息断定.
 * <p>
 * Copyright: Copyright (c) Nov 22, 2010 10:08:41 AM
 * <p>
 * Company: 北京宽连十方数字技术有限公司
 * <p>
 * 
 * @author suncg@c-platform.com
 * @version 1.0.0
 */
public class Result {

	public final static Result SUCCESS = Result.valueOf(true);

	public final static Result FAILURE = Result.valueOf(false);

	private boolean success;

	private final String message;

	private boolean alert;

	private Result(boolean success, String message) {
		this.success = success;
		this.message = message;
	}

	private Result(boolean success, String message, boolean alert) {
		this.message = message;
		this.alert = alert;
		this.success = success;
	}

	public static Result valueOf(boolean success) {
		return new Result(success, null);
	}

	public static Result valueOf(boolean success, String message) {
		return new Result(success, message);
	}

	public static Result valueOf(boolean success, String message, boolean alert) {
		return new Result(success, message, alert);
	}

	public String getMessage() {
		return message;
	}

	public boolean success() {
		return success;
	}

	public boolean failure() {
		return !success;
	}

	@Override
	public String toString() {
		return String.format("%s : alert : %s, message : %s", success ? "SUCCESS" : "FAILURE", alert, message);
	}
}